package com.example.mymatch.service.Imp;

import com.example.mymatch.dao.IPm;
import com.example.mymatch.model.Pm;
import com.example.mymatch.service.IPmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 对服务接口规范的方法实现
 * 编写者：谢楷诗
 */
@Service
public class IPmServiceImpl implements IPmService {
    @Autowired
    private IPm pmMapper;
    @Override//添加方法
    public int insertPm(Pm pm){
        int pmValue=0;
        //查看当前党员名称不能重复
        Pm pm1=new Pm();
        pm1.setPmName(pm.getPmName());
        List<Pm> getC =pmMapper.getAllPm(pm1);
        if (getC.size()>=1){
            //不可以添加党员名称
            pmValue=-1;
        }else {
            pmValue=pmMapper.insertPm(pm);
        }
        return pmValue;
    }
    @Override
    public List<Pm> getAllPm(Pm pm){return pmMapper.getAllPm(pm);}
    @Override
    public int updatePm(Pm pm){
        int pmValue=0;
        //判断主键不能为0
        if (pm.getPmId()!=0){
            //主键信息必须存在

            //名称不能重复

            pmValue=pmMapper.updatePm(pm);
        }
        return pmValue;
    }
    @Override
    public int deletePm(Pm pm){
        int pmValue=0;
        //判断主键不能为0
        if (pm.getPmName()!= null){
            //主键是否与其他表有关联，如果关联，则先删除其它表的信息，或者给出此条信息不允许被删

            pmValue=pmMapper.deletePm(pm);
        }
        return pmValue;
    }

    //单条查询
    @Override
    public Pm getPm(Pm pm){
        Pm pm1=new Pm();
        if (pm.getPmName()!= null){
            pm1=pmMapper.getPm(pm);
        }
        return pm1;
    }
}

